__author__ = 'l4537'
#coding:utf-8
import re,json
def Re(res,total,id = "1"):
    #1.普通模式正则，2，多行模式正则
    if id == "1":
        data = re.findall(str(res),total)
    if id == "2":
        data = re.findall(str(res),total,re.S)
    return data
#含有板卡的光交，长port
def Liuliang(text):
    data = Re("(slot\s\d+:)((\s+\S+){16})", text, "2")
    # 老的data = Re("===========((\s+\S+){16})",a.read(),"2")
    list = []
    for i in data:
        list.append(i[0])
    list = set(list)
    slotdata = {}
    for i in list:
        alist = ""
        num = Re("\d+", i)
        slotdata[int(num[0])] = {}
        for k in data:
            if i == k[0]:
                alist = alist + k[1]
        a = 0
        for zzz in Re("\s+(\S+)", alist):
            slotdata[int(num[0])][a] = zzz
            a += 1
    return slotdata
#没有板卡的光交，只有port
def liuliang_mini(text):
    slotdata ={}
    data = Re("===========((\s+\S+){16})",text,"2")
    da = ''
    for i in data:
        da = da + i[0]
    dad2 = Re("\S+",da)
    num = 0
    for d in dad2:
        slotdata[num] = d
        num += 1
    return slotdata



